//
//  MainTabBarController.m
//  ErmaoDJ
//
//  Created by NextStep on 2017/12/26.
//  Copyright © 2017年 NextStep. All rights reserved.
//

#import "MainTabBarController.h"
#import "UIView+Extension.h"
#import "MainNavController.h"
#import "HomeViewController.h"
#import "DiscoveryViewController.h"
#import "LuessViewController.h"
#import "MineViewController.h"
#import "MainTabBar.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initialController];
    
}

-(void) initialController {
    HomeViewController *homeVC = [HomeViewController new];
    [self addChildViewController:homeVC imageNamed:@"discovery" title:@"首页"];
    DiscoveryViewController *discoveryVC = [DiscoveryViewController new];
    [self addChildViewController:discoveryVC imageNamed:@"home" title:@"发现"];
    LuessViewController *luessVC = [LuessViewController new];
    [self addChildViewController:luessVC imageNamed:@"page" title:@"文章"];
    MineViewController *mineVC = [MineViewController new];
    [self addChildViewController:mineVC imageNamed:@"us" title:@"我"];
    MainTabBar *tabBar = [MainTabBar new];
    [self setValue:tabBar forKey:@"tabBar"];//把系统的tabBar替换成我们自己定义的tabBar。tabBar是readonly属性 只能KVC赋值
}


-(void) addChildViewController:(UIViewController *)childController imageNamed:(NSString *) imageNamed title:(NSString *) title{
    //图片渲染模式
    childController.tabBarItem.image = [[UIImage imageNamed:[NSString stringWithFormat:@"%@",imageNamed]] imageWithRenderingMode:UIImageRenderingModeAutomatic];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"selected_%@",imageNamed]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置标题
    childController.title = title;
    //设置文字属性
    //普通模式
    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
    //选中模式
    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
    //包装navigationController
    MainNavController *nav = [[MainNavController alloc] initWithRootViewController:childController];
    [self addChildViewController:nav];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
